/**
 * 
 */

function gotoNewPage(newUrl)
{
	showPreloader(true);
	window.location = newUrl;
}

function loadHomeVideo()
{
	var videoURL = "http://player.vimeo.com/video/49740813?title=0&byline=0&portrait=0&autoplay=1;";
	$.get(videoURL, function(data) {
    	$( "#headerDisplay" ).empty().append( data );
    });
}

function contentDisplayText(isFullText)
{
	showPreloader(true);
	if(isFullText)
	{
		getCMSContent({method:"RECORD", cmsRef:"ct_id", cmsValue:"1", eventId:"1", displayType:"full"}, $("#contentDisplay"), isFullText);
		$("#contentReadMore").empty();
		$("#contentReadMore").hide();
	}
	else
		getCMSContent({method:"RECORD", cmsRef:"ct_id", cmsValue:"1", eventId:"1", displayType:"short"}, $("#contentDisplay"), isFullText);
}

function getCMSContent(cmsParam, target, isFullText)
{
	var cmsURL = "pages/cmsContent.php";
	
	$.post(cmsURL, cmsParam, function(data) {
    	$(target).empty().append( data );
    	showPreloader(false);
    });
}

function getLoginForm()
{
	showPreloader(true);
	var url = "loginform.php";
	
	$.post(url, function(data) {
		showLoginDiv(true);
    	$( "#loginDisplay" ).empty().append( data );
    	showPreloader(false);
    	
    });
}

function showLoginDiv(isVisible)
{
	if(isVisible)
	{
		$("#loginDisplay").show();
		$("#menuContent").hide();
	}
	else
	{
		$("#menuContent").show();
		$("#loginDisplay").hide();
	}
}

function validateLogin()
{
	var loginParams = {};
	loginParams.username = $("#loginContent").find( 'input[name="username"]' ).val();
	loginParams.password = $("#loginContent").find( 'input[name="password"]' ).val();
	loginParams.password = $.sha1(loginParams.password);
	loginParams.token = $("#loginContent").find( 'input[name="tokenNumber"]' ).val();
	
	$("#emailErrorMsg").empty().append("");
	$("#passwordErrorMsg").empty().append("");
	
	if(loginParams.username == "")
	{
		$("#emailErrorMsg").empty().append("Enter your email address.");
		return;
	}
	
	if(loginParams.password == "")
	{
		$("#passwordErrorMsg").empty().append("Enter your password.");
		return;
	}
	
	showPreloader(true);
	$.post("login.php", loginParams, function(data) {
		
		if(data == 0)
			window.location = "pages/register.php";
		else if(data == 1)
			window.location = "main.php";
		else
		{
			$("#passwordErrorMsg").empty().append(data);
			showPreloader(false);
		}
    });
}